package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.StrategySecondaryComment;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.StrategySecondaryCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategySecondaryCommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 攻略点评控制器
 */
@RestController
@RequestMapping("/strategyComments")
public class StrategyCommentController {
    @Autowired
    private IStrategyCommentService strategyCommentService;
    @Autowired
    private IStrategySecondaryCommentService strategySecondaryCommentService;

    /**
     * 根据评论id获取评论信息以及评论的用户信息和对应的评论攻略信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public StrategyComment get(@PathVariable Long id){
        return strategyCommentService.get(id);
    }

    /**
     * 首页头条点评获取最新三条点评数据
     * @param qo
     */
    @GetMapping
    public PageInfo query(StrategyCommentQueryObject qo){
        qo.setOrderBy("sc.createTime desc");
        qo.setPageSize(3);
        return strategyCommentService.query(qo);
    }


    /**
     * 攻略二级评论分页高查
     * @param qo
     * @return
     */
    @GetMapping("/{commentId}/secondaryComments")
    public PageInfo query(StrategySecondaryCommentQueryObject qo){
        qo.setOrderBy("ssc.creatTime desc");
        return strategySecondaryCommentService.query(qo);
    }

    /**
     * 新增一条攻略二级评论
     * @param strategySecondaryComment
     * @return
     */
    @PostMapping("/{strategycomment.id}/secondaryComments")
    public JSONResult save(StrategySecondaryComment strategySecondaryComment){
        strategySecondaryCommentService.save(strategySecondaryComment);
        return new JSONResult();
    }
}